function checkToken({
	cbIfHasToken = null,
	pathForGoingBack = "",
	isTabBarPage = true
} = {}) {
	let token = uni.getStorageSync('token')
	if (token) {
		// 继续预览页面,包括发送请求等操作
		if (typeof cbIfHasToken === 'function') {
			// 有token的事件逻辑
			cbIfHasToken()
		}
	} else {
		// 跳转到我的页面去登录
		uni.switchTab({
			url: '../myUser/myUser',
			success: () => {
				// 把当前路径存储起来,登录之后可以跳转回去
				uni.setStorageSync('pathForGoingBack', pathForGoingBack)
				// 页面路径类型,为了区分是tabBar页面还是普通页面,二者跳转方式不同
				uni.setStorageSync('isTabBarPage', isTabBarPage)
				setTimeout(() => {
					uni.showToast({
						title: "请先登录",
						icon: 'none'
					})
				}, 200)
			}
		})
	}
}

function goBackAfterLogin() {
	let pathForGoingBack = uni.getStorageSync('pathForGoingBack')
	let isTabBarPage = uni.getStorageSync('isTabBarPage')
	// 判断登录后要不要跳转到某个页面
	if (pathForGoingBack) {
		// 判断往回跳转的页面的类型
		if (isTabBarPage) {
			uni.switchTab({
				url: pathForGoingBack,
				success: () => {
					uni.removeStorageSync('pathForGoingBack')
					uni.removeStorageSync('isTabBarPage')
				}
			})
		} else {
			uni.redirectTo({
				url: pathForGoingBack,
				success: () => {
					uni.removeStorageSync('pathForGoingBack')
					uni.removeStorageSync('isTabBarPage')
				}
			})
		}
	}
}

export {
	checkToken,
	goBackAfterLogin
}
